package com.example.consumer.controller;

import com.example.consumer.client.ProviderClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/consumer")
public class ConsumerController {

    @Autowired
    private ProviderClient providerClient;

    @Value("${server.port}")
    private String serverPort;

    @Value("${spring.application.name}")
    private String applicationName;

    @GetMapping("/test-load-balance")
    public Map<String, Object> testLoadBalance() {
        Map<String, Object> result = new HashMap<>();
        result.put("consumerInfo", "Consumer Service - Port: " + serverPort);
        result.put("providerResponse", providerClient.hello());
        result.put("timestamp", System.currentTimeMillis());
        return result;
    }

    @GetMapping("/provider-info")
    public Map<String, Object> getProviderInfo() {
        Map<String, Object> result = new HashMap<>();
        result.put("consumerInfo", "Consumer Service - Port: " + serverPort);
        result.put("providerInfo", providerClient.getInfo());
        result.put("timestamp", System.currentTimeMillis());
        return result;
    }

    @GetMapping("/health")
    public Map<String, Object> health() {
        Map<String, Object> result = new HashMap<>();
        result.put("serviceName", applicationName);
        result.put("port", serverPort);
        result.put("status", "UP");
        result.put("message", "Consumer Service is running");
        return result;
    }
} 